package com.magnusart.scrumppm.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

import com.magnusart.scrumify.dao.CommonDAO;
import com.magnusart.scrumify.dao.DAOFactory;
import com.magnusart.scrumppm.model.Project;
import com.magnusart.scrumppm.model.ProjectBuilder;
import com.magnusart.scrumppm.presenters.GlobalEvents;
import com.magnusart.scrumppm.presenters.ProjectDetailsPresenter;

final class MiddleFrame extends Composite
{
	private final TabFolder tabbedViews;
	private final TabItem overviewView;
	private final TabItem sprintsView;
	private final TabItem storiesView;
	private final TabItem tasksView;
	private final TabItem tagsView;
	private final ProjectDetails projectDetails;
	private final CommonDAO<Project, Project, ProjectBuilder> projectDao;
	
	MiddleFrame( Composite parent ) {
		super( parent, SWT.None );
	}


	{ /* Initialization block */
		// Create the tab folder
		tabbedViews = new TabFolder( this , SWT.FLAT );
		tabbedViews.setLayout( new FillLayout() );
		
		// Create the individual tabs
		overviewView = new TabItem ( tabbedViews , SWT.NONE);
		sprintsView = new TabItem( tabbedViews, SWT.NONE );
		storiesView = new TabItem( tabbedViews, SWT.NONE );
		tasksView = new TabItem( tabbedViews, SWT.NONE );	
		tagsView = new TabItem( tabbedViews, SWT.NONE );
		
		setLayout( new FillLayout() );

		projectDetails = new ProjectDetails( tabbedViews );
		projectDao = DAOFactory.getDAOFactory().getProjectDAO();
		ProjectDetailsPresenter projectDetailsPresenter = new ProjectDetailsPresenter( projectDetails, projectDao );
		GlobalEvents.observe().addObserver( projectDetailsPresenter );

		overviewView.setText( "Overview" );
		sprintsView.setText( "Sprints" );
		storiesView.setText( "Stories" );
		tasksView.setText( "Tasks" );
		tagsView.setText( "Tags" );
	
		overviewView.setControl( projectDetails );
	}
}